//api/login.js
'use strict';
const Controller = require('egg').Controller;
class LoginController extends Controller {
    async index() {
        const { ctx } = this;
        // console.log(ctx.request.body)
        var {name,pass} = ctx.request.body
        var res = await ctx.model.User.find({name,pass});
        if(res.length){

            ctx.cookies.set("name",name,{
                httpOnly:false//默认为true,设置cookie在前端可读
            })

            ctx.body ={
                msg:"登陆成功",
                code:200,
                name
            }
        }else{
            ctx.body ={
                msg:"登陆失败，用户名或密码错误",
                code:400,
            }
        }
    }
}

module.exports = LoginController;
